package controller

import (
	"cloud-storage/global"
	"cloud-storage/model/mysql"
	"cloud-storage/utils/response"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// Index 获取该用户仓库的详细信息
func Index(c *gin.Context) {
	phone := global.GetPhone(c)
	//获取用户信息
	user, err := mysql.GetUserInfo(phone)
	if err != nil {
		zap.L().Error("mysql.GetUserInfo() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeSelectOperationFail)
		return
	}
	//获取用户仓库信息
	userFileStore, err := mysql.GetUserFileStore(user.Id)
	if err != nil {
		zap.L().Error("mysql.GetUserFileStore() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeSelectOperationFail)
		return
	}
	//获取用户文件数量
	fileCount, err := mysql.GetUserFileCount(user.FileStoreId)
	if err != nil {
		zap.L().Error("mysql.GetUserFileCount() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeOperationFail)
		return
	}
	//获取用户文件夹数量
	fileFolderCount, err := mysql.GetFileFolderCount(user.FileStoreId)
	if err != nil {
		zap.L().Error("mysql.GetFileFolderCount() failed err:", zap.Error(err))
		response.ResponseError(c, response.CodeOperationFail)
		return
	}
	//获取用户文件使用明细情况
	fileDetailUse := mysql.GetFileDetailUser(user.FileStoreId)

	response.ResponseSuccess(c, gin.H{
		"user":            user,
		"currIndex":       "active",
		"userFileStore":   userFileStore,
		"fileCount":       fileCount,
		"fileFolderCount": fileFolderCount,
		"fileDetailUse":   fileDetailUse,
	})

}
